/**
 * @summary 底图切换组件
 */
define([
	"dojo/_base/declare",
	"dojo/_base/array",
	"dojo/dom-attr",
	"dojo/dom-construct",
	"dojo/dom-class",
	"dojo/dom-style",
	"dojo/query",
	"dojo/_base/fx",
	"dojo/fx",
	"require",
	"dijit/_WidgetBase",
	"dijit/_TemplatedMixin",
	"dijit/_WidgetsInTemplateMixin",
	"dojo/text!./basemapGallery.html","dojo/mouse",
	"dojo/on",
	"widget/utils"
], function(declare, array, domAttr, domConstruct, domClass, domStyle, query, basefx, fx, require, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, template,mouse, on, utils) {
	utils.importCss(require.toUrl("./basemapGallery.css"));
	return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
		templateString: template,
		baseClass: "basemapGallery",
		on3DShow:null,
		onMouseenter:null,
		onMouseleave:null,
		postCreate: function() {
			this.initBasemapGallery();
			this.addListeners();
			this.inherited(arguments);
		},
		initBasemapGallery: function() {
			var self = this;
			var vector = domConstruct.create("img", {
				title: "矢量",
				identity: "vectormap",
				"class": "top",
				src: require.toUrl("./images/sl.png")
			});
			self.domNode.appendChild(vector);
			var image = domConstruct.create("img", {
				title: "影像",
				identity: "imagemap",
				src: require.toUrl("./images/yx.png")
			});
			self.domNode.appendChild(image);
		},
		addListeners: function() {
			var self = this;
			var refNode = self.domNode,
				gallerys = query("img", refNode),
				map = self.map;
			//on(this.galleryBox, "mouseenter", function() {
				on(self.galleryBox, mouse.enter, function() {
					//debugger;
				basefx.animateProperty({
					node: refNode,
					properties: {
						width: {
							end: 80,
							start: 0
						}
					}
				}).play();
				fx.slideTo({
					node: gallerys[1],
					left: "80",
					top: "0",
					units: "px"
				}).play();
				self.onMouseenter ? self.onMouseenter() : null;
			});
			//on(this.galleryBox, "mouseout", function() {
				on(self.galleryBox, mouse.leave, function() {
				
				basefx.animateProperty({
					node: refNode,
					properties: {
						width: {
							end: 0,
							start: 80
						}
					}
				}).play();
				fx.slideTo({
					node: gallerys[1],
					left: "0",
					top: "0",
					units: "px"
				}).play();
				self.onMouseleave ? self.onMouseleave() : null;
			});
			array.forEach(gallerys, function(gallery) {
				on(gallery, "click", function(evt) {
					array.forEach(gallerys, function(item) {
						var identity = domAttr.get(item, "identity");
						var flag = domAttr.get(evt.target, "identity") === identity;
						if(flag) {
							domClass.add(item, "top");
						} else {
							domClass.remove(item, "top");
						}
					});
					var curIdentity=domAttr.get(evt.target, "identity");
					//debugger
					if(curIdentity=="vectormap"){
						var vectormap = map.getLayer("vectormap");
						vectormap ? vectormap.setVisibility(true) : null;
						var imagemap = map.getLayer("imagemap");
						imagemap ? imagemap.setVisibility(false) : null;
					}else{
						var vectormap = map.getLayer("vectormap");
						vectormap ? vectormap.setVisibility(false) : null;
						var imagemap = map.getLayer("imagemap");
						imagemap ? imagemap.setVisibility(true) : null;
					}
				});
			});
		}
	});
});
